home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / pctchnqs / 1992 / number1 / keyfast.asm < prev    next >
Assembly Source File  |  1992-02-05  |  4KB  |  77 lines

  1. IDelay  =       7             ; Initial delay (clock ticks).
  2. RDelay  =       1             ; Repeat key delay (clock ticks).
  3. CSeg            segment
  4.                 org 100h
  5. assume cs:CSeg,ds:nothing,es:nothing
  6. Install:;>>>>>>>>>>>> Installation <<<<<<<<<<<<<<<<<<<<<<<<<
  7.         xor     ax,ax
  8.         mov     es,ax               ; Set to start of vectors.
  9.         lds     ax,dword ptr es:[4*08h]; Get vector for clock.
  10.         cmp     ax,offset Intercept08h; Check if already set up.
  11.         je      SI60                ; Exit to DOS if already there.
  12.         cli                         ; Turn off the interrupts.
  13.         mov     cs:OldVec,ax        ; Save the old vector.
  14.         mov     cs:OldVec+2,ds
  15.         mov     word ptr es:[4*08h],offset Intercept08h
  16.         mov     es:[4*08h+2],cs
  17.         lds     ax,dword ptr es:[4*09h]; Get vector for keyboard.
  18.         mov     cs:OldVec+4,ax      ; Save the old vector.
  19.         mov     cs:OldVec+6,ds
  20.         mov     word ptr es:[4*09h],offset Intercept09h
  21.         mov     es:[4*09h+2],cs
  22.         mov     dx,offset Exit08h+32; Save this many bytes.
  23.         int     27h                 ; Terminate and Stay Resident.
  24. SI60:   int     20h                 ; Exit to DOS.
  25. ; >>>>>>>>>>>>>>>>>>>>> Data Storage <<<<<<<<<<<<<<<<<<<<<<<
  26. BIOSD           dw      40h         ; BIOS_Data segment.
  27. RepeatCNT       db      0           ; Repeat count.
  28. RepeatChar      dw      0           ; Repeat character here.
  29. OldVec          dw      0,0,0,0     ; Old Timer & Keyboard vectors.
  30. Intercept09h:;>> Intercept Keyboard Routine <<<<<<<<<<<<<<<<
  31.         push    ds                  ; Save registers.
  32.         push    bx
  33.         mov     ds,cs:BIOSD         ; Set DS to BIOS data segment.
  34.         mov     cs:RepeatCNT,0      ; Stop Repeat for now.
  35.         mov     bx,ds:[1ch]         ; Pick up tail (at 40h:1ch).
  36.         pushf                       ; Dummy up an interrupt.
  37.         call    dword ptr cs:OldVec+4; Go to regular routine.
  38.         cmp     bx,ds:[1ch]         ; Did tail Change?
  39.         jne     NewKey              ; Yes, a new key to consider.
  40.         mov     cs:RepeatChar,0     ; So won't match anything.
  41.         jmp     short Exit09h       ; Exit with repeat off.
  42. NewKey: mov     bx,[bx]             ; Pick up key typed.
  43.         or      bh,bh               ; Zero scan code indicates Alt
  44.         jz      Exit09h             ; created keys which are skipped.
  45.         cmp     bx,cs:RepeatChar    ; Present repeat key?
  46.         mov     cs:RepeatChar,bx    ; Store as repeat key.
  47.         mov     cs:RepeatCnt,IDelay ; Assume initial delay.
  48.         jne     Exit09h             ; A new key.
  49.         mov     cs:RepeatCnt,RDelay ; Change to Repeat delay.
  50. Exit09h:pop     bx                  ; Restore registers.
  51.         pop     ds
  52.         iret
  53. Intercept08h:;>>> Intercept Timer Interrupt <<<<<<<<<<<<<<<<
  54.         dec     cs:RepeatCNT        ; Time to repeat?
  55.         jg      Exit08h             ; Not time to repeat.
  56.         mov     cs:RepeatCNT,0      ; Reset for next time.
  57.         jl      Exit08h             ; Not repeating.
  58. I08h00: push    ds                  ; Repeat the character.
  59.         push    bx
  60.         mov     ds,cs:BIOSD         ; Segment of buffer.
  61.         mov     bx,ds:[1ch]         ; Get tail (at 40h:1ch).
  62.         add     bx,2                ; Bump pointer.
  63.         cmp     bx,ds:[82h]         ; Check buffer end (at 40h:82h).
  64.         jne     I08h1               ; Not at end of buffer.
  65.         mov     bx,ds:[80h]         ; Buffer start (at 40h:80h).
  66. I08h1:  cmp     bx,ds:[1ah]         ; Check head (at 40h:1ah).
  67.         je      I08h50              ; Exit if buffer is full.
  68.         push    cs:RepeatChar       ; Pick up character to repeat.
  69.         xchg    ds:[1ch],bx         ; Update tail.
  70.         pop     word ptr [bx]       ; Put character in buffer.
  71.         mov     cs:RepeatCNT,RDelay ; Set repeat delay count.
  72. I08h50: pop     bx                  ; Restore registers.
  73.         pop     ds
  74. Exit08h:jmp     dword ptr cs:OldVec ; Go to regular routine.
  75. CSeg    ends
  76.         end     Install
  77.